/*********************************************************************************
 *      Copyright:  (C) 2022 Li Yanting<liyanting2@163.com>
 *                  All rights reserved.
 *
 *       Filename:  get_time.c
 *    Description:  This file 
 *                 
 *        Version:  1.0.0(04/18/2022)
 *         Author:  Li Yanting <liyanting2@163.com>
 *      ChangeLog:  1, Release initial version on "04/18/2022 12:46:29 AM"
 *                 
 ********************************************************************************/

#include "client_func.h"


/*********************************************************************************
 *      function name:  get_format_time
 *        Description:  Set current time to format time.
 *       return value:  Return current format time.
 *          parameter:  current time.
 ********************************************************************************/
char * get_format_time(long current_time)
{
    static char           buf[128];
    struct tm            *p;
	time_t                timep;
	timep = (time_t)current_time;

    p=gmtime(&timep);
	
	sprintf(buf, "%d-%d-%d %d:%d:%d", 1900+p->tm_year, 1+p->tm_mon, p->tm_mday, 8+p->tm_hour, p->tm_min, p->tm_sec);

	return buf;
}

#if 0
    printf("%d\n",p->tm_sec);            /*获取当前秒*/
    printf("%d\n",p->tm_min);            /*获取当前分*/
    printf("%d\n",8+p->tm_hour);         /*获取当前时,这里获取西方的时间,刚好相差八个小时*/
    printf("%d\n",p->tm_mday);           /*获取当前月份日数,范围是1-31*/
    printf("%d\n",1+p->tm_mon);          /*获取当前月份,范围是0-11,所以要加1*/
    printf("%d\n",1900+p->tm_year);      /*获取当前年份,从1900开始，所以要加1900*/
    printf("%d\n",p->tm_yday);           /*从今年1月1日算起至今的天数，范围为0-365*/
#endif


/*********************************************************************************
 *      function name:  get_time
 *        Description:  Assign a value to an address
 *       return value:  Get second from 1970.01.01 00:00:00
 *          parameter:  A address
 ********************************************************************************/
void get_time(long *current_time)
{
   *current_time = (long)time(NULL);
}

/*********************************************************************************
 *      function name:  print_usage
 *        Description:  print usage imformation
 *       return value:  No.
 *          parameter:  Process name(agrv[0]).
 ********************************************************************************/
void print_usage(char *progname)
{
    printf("%s usage:\n", progname);
    printf("-i(--cli_ip): specfy the cli_ip.\n");
    printf("-p(--cli_port): specfy the cli_port.\n");
    printf("-t(--interval_time): set the interval time(second) of collect temperature.\n");
    printf("-n(--HOST_NUMBER): set the name of HOST.\n");
    printf("-b(--daemon): set the program running in the background\n");
    printf("-h(--help): print this help information.\n");
    printf("example: %s -i 127.0.0.1 -p 12345 -t 30 -n RPI_00001 -b\n", progname);

    return ;
}
